package com.gs.cd.service.role.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.gs.cd.service.role.model.AuthRoleResourceGroup;
import com.gs.cd.service.role.mapper.AuthRoleResourceGroupMapper;
import com.gs.cd.service.role.service.AuthRoleResourceGroupService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.NonNull;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author seven
 * @since 2020-12-22
 */
@Service
public class AuthRoleResourceGroupServiceImpl extends ServiceImpl<AuthRoleResourceGroupMapper, AuthRoleResourceGroup> implements AuthRoleResourceGroupService {

    @Override
    public List<AuthRoleResourceGroup> listByRoleCode(String roleCode, String tenantCode) {
        return list(new QueryWrapper<AuthRoleResourceGroup>().lambda().eq(AuthRoleResourceGroup::getRoleCode, roleCode)
                .eq(AuthRoleResourceGroup::getTenantCode, tenantCode));
    }

    @Override
    public List<AuthRoleResourceGroup> listByRoleCodes(@NonNull Collection<String> roleCodes, String tenantCode) {
        if (roleCodes.isEmpty()) {
            return new ArrayList<>();
        }
        return list(new QueryWrapper<AuthRoleResourceGroup>().lambda().eq(AuthRoleResourceGroup::getTenantCode, tenantCode)
                .in(AuthRoleResourceGroup::getRoleCode, roleCodes));
    }
}
